package com.ha.mapper;

import com.github.pagehelper.Page;
import com.ha.annotation.AutoFill;
import com.ha.dto.GarbagePageDTO;
import com.ha.entity.Garbage;
import com.ha.entity.GarbageKind;
import com.ha.enumeration.OperationType;
import com.ha.vo.GarbageVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * ClassName: garbageMapper
 * Package: com.ha.mapper
 * Description:
 *
 * @Author 那啥啥
 * @Create 2024/4/21  14:01
 * @Version 1.0
 */
@Mapper
public interface GarbageMapper {

    Page<GarbageVO> pageQuery(GarbagePageDTO garbagePageDTO);

    @Select("select *from rubbish where id = #{id}")
    Garbage getById(Long id);

    @Select("select *from rubbish where name = #{name}")
    Garbage getByName(String name);

    @AutoFill(OperationType.UPDATE)
    void update(Garbage garbage);

    @Delete("delete from rubbish where id = #{id}")
    void deleteById(Long id);

    @AutoFill(OperationType.INSERT)
    @Insert("insert into rubbish(rubbish_kind_id, name, introduction, image," +
            " create_time, update_time, update_user, create_user) values " +
            "(#{rubbishKindId},#{name},#{introduction},#{image}," +
            "#{createTime},#{updateTime},#{updateUser},#{createUser})")
    void addGarbage(Garbage garbage);

    @Select("select *from rubbish where rubbish_kind_id = #{id} ")
    List<Garbage> getByKind(Long id);
}
